package priv.yiyuan.example.composite.approver2;

/**
 * 员工
 * <p>
 * 组合模式-叶子节点/责任链模式-具体处理者
 *
 * @author YiYuan
 * @data 2025/8/29
 * @apoNote
 */
public class Employee implements Approver {

    private String name;

    private int approvalLimit;

    private Approver nextApprover;

    public Employee(String name, int approvalLimit) {
        this.name = name;
        this.approvalLimit = approvalLimit;
    }

    @Override
    public void handleRequest(LeaveRequest request) {

        if (request.getDays() <= approvalLimit) {
            System.out.println(name + " 批准了 " + request.getEmployeeName() + " 的 " + request.getDays() + " 天请假申请。");
        }
        else if (nextApprover != null) {
            System.out.println(name + " 无法批准, 转交给 " + nextApprover.getName());
            nextApprover.handleRequest(request);
        }
        else {
            System.out.println("无人能审批 " + request.getEmployeeName() + " 的 " + request.getDays() + " 天请假申请。");
        }

    }

    @Override
    public void setNextApprover(Approver nextApprover) {
        this.nextApprover = nextApprover;
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public int getApprovalLimit() {
        return this.approvalLimit;
    }
}
